<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <!--{include file='comm/header.tpl'}-->

    <title>生产查询</title>

    <!--{include file='comm/comm_cal.tpl'}-->
    <!--{include file="comm/comm_multiselect.tpl"}-->
    <script src="/quanliadmin/docroot/js/createreoprt.js"></script>
<style>
    #e_layer {
        top: 20px;
    }
</style>
</head>

<body>

<div class="container">

    <div class="comm_content">
            <div class="search-box">
                <div style="position:relative">
                    <form method="post" class="form-inline" onsubmit="return false;" id="search_form">
                        <table>
                            <tbody>
                            <tr>
                                <td height="27px">
                                    <span>配送日期：<input type="text" class="form-control input-sm" style="width: 140px;" value="<!--{$date}-->" name="send_date" id="send_date"></span>
                                    <span>
                                        配送开始时间：
                                        <select name="send_start_time" id="send_start_time" class="form-control input-sm" style="width:100px;">
                                            <option value="">请选择</option>
                                            <!--{foreach from = $sendStartTime_array item = val}-->
                                                <option value="<!--{$val.itemName}-->"><!--{$val.itemName}--></option>
                                            <!--{/foreach}-->

                                        </select>
                                    </span>

                                    <span>
                                        配送结束时间：
                                        <select name="send_start_time_end" id="send_start_time_end" class="form-control input-sm" style="width:100px;">
                                            <option value="">请选择</option>
                                            <!--{foreach from = $sendEndTime_array item = val}-->
                                                <option value="<!--{$val.itemName}-->"><!--{$val.itemName}--></option>
                                            <!--{/foreach}-->
                                        </select>
                                    </span>

                                    <span>
                                       配送城市：<select id="cityID" name="cityID" class="form-control input-sm" style="width:100px;">
                                            <option value="">请选择</option>

                                        </select>
                                    </span>

                                    <span>
                                        配送站：
                                        <select name="distribution_id" id="distribution_id" class="form-control input-sm" style="width:110px;">
                                            <option value="">请选择</option>
                                        </select>
                                    </span>

                                    <span>
                                        订单类型：
                                        <select name="billType" id="billType" class="form-control input-sm" style="width:115px;">
                                            <option value="all">全部</option>
                                            <!--{foreach from=$global_array.bill_type item=bill_type_name key=bill_type}-->
                                                <option value="<!--{$bill_type}-->"><!--{$bill_type_name.name}--></option>
                                            <!--{/foreach}-->
                                        </select>
                                    </span>
                                    <input type="hidden" id="bill_type" name="bill_type" value=""/>

                                    <span>订单状态：<select id="bill_status" class="form-control input-sm"  name="bill_status" style="width:120px;">
                                            <option value="all">全部</option>
                                            
                                            
                                            <!--mod by yim.hu 20141127 FUN-BK-0035 订单状态优化--start -->
	                                            <!--<option value="1">确认</option>-->
	                                            <!--<option value="2">生产</option>-->
	                                            <!--<option value="3">入库</option>-->
	                                            <!--<option value="4">上车</option>-->                                           
                                            <option value="1">已确认</option>
                                            <option value="2">已打印生产单</option>
                                            <option value="3">已质检入库</option>
                                            <option value="4">已上车</option>                                            
                                            <!--mod by yim.hu 20141127 FUN-BK-0035 订单状态优化--end -->
                                        </select>
                                    </span>

                                    <input type="hidden" id="billStatus" name="billStatus" value=""/>

                                    <span>订单编号：<input type="text" class="form-control input-sm" style="width:140px" value="" name="bill_code" id="bill_code"></span>
                                    <span>SKU/品名：<input type="text" class="form-control input-sm" style="width:140px" value="" name="sku" id="sku"></span>

                                    <span>
                                        是否切分：
                                        <select name="segmentation" id="segmentation" class="form-control input-sm" style="width:70px;">

                                            <option value="">全部</option>
                                            <option value="1">是</option>
                                            <option value="0">否</option>

                                        </select>
                                    </span>

                                    <span>
                                        含生日牌：
                                        <select name="birthday_card" id="birthday_card" class="form-control input-sm" style="width:70px;">

                                            <option value="">全部</option>
                                            <option value="1">是</option>
                                            <option value="0">否</option>

                                        </select>
                                    </span>

                                    <span>
                                        是否打印：
                                        <select name="print_num" id="print_num" class="form-control input-sm" style="width:70px;">

                                            <option value="">全部</option>

                                            <option value="1">是</option>
                                            <option value="0">否</option>

                                        </select>
                                    </span>

                                    <span><input type="button" onclick="productSearch.search();" class="btn btn-primary" value="刷新"></span>

                                    <!--{if $edit_permission}-->
                                        <span><input  value="直接打印生产单"  onclick="productSearch.brandPrintCheck(2);" class="btn btn-default" type="button"></span>
                                        <span style="display: none;"><input  value="预览生产单"  onclick="productSearch.brandPrintCheck(1);" class="btn btn-default" type="button"></span>
                                    <!--{/if}-->

                                    <span><input type="button"  onclick="productSearch.reSet();" class="btn btn-warning" value="重置"></span>

                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none;"></table>
        </div>
    
    <!--{include file='comm/footer.tpl'}-->

</div>
<script type="text/javascript">

CreateReport("Report");

$('#send_date').datepicker();

var table_id = <!--{$table_id}-->;

var fixed_json = <!--{$fixed_json}-->;

$("#flex").flexigrid({
    url:"/invokingAjax-backend/production/productionSearch.ajax?operFlg=1",
    dataType: "json",
    colModel : fixed_json,
    sortname: "product_code,goods_spec,print_time",
    sortorder: "asc",
    usepager: true,
    rp: 20,
    rpOptions: [10, 15, 20, 25, 30, 50],
    useRp: true,
    showTableToggleBtn: true,
    autoload: true,
    onSubmit: function() {
        var dt = $('#search_form').serializeArray();
        $("#flex").flexOptions({params: dt});
        return true;
    },

    //拉伸宽度后触发
    onColResize:function(){

        var last_cid = arguments[0];
        var width = arguments[1];

        E.ajax_get({
            url:'/invokingAjax-backend/system/flexigrid.ajax?operFlg=1',
            data:{
                table_id:table_id,
                last_cid:last_cid,
                width:width
            },
            call:function( o ){ }

        });

    },

    //隐藏后触发
    onToggleCol:function(){

        var cid = arguments[0];
        var hide = arguments[1];

        E.ajax_get({
            url:'/invokingAjax-backend/system/flexigrid.ajax?operFlg=3',
            data:{
                table_id:table_id,
                cid:cid,
                hide:hide
            },
            call:function( o ){ }

        });

    },

    //拖拽后触发
    onDragCol:function(){

        var cid = arguments[0];
        var last_cid = arguments[1];

        E.ajax_get({
            url:'/invokingAjax-backend/system/flexigrid.ajax?operFlg=2',
            data:{
                table_id:table_id,
                cid:cid,
                last_cid:last_cid
            },
            call:function( o ){ }

        });

    }

});

$(document).on('click',"#allChecked", function(){
    if( this.checked ){
        //全选
        $("input[name='billArr[]']").each(function(){
            this.checked = true;
        })
    }else{
        //全不选
        $("input[name='billArr[]']").each(function(){
            this.checked = false;
        })
    }
});

$('#billType').multiselect();
$('#bill_status').multiselect();
var productSearch= {
    print_array:'', //订单号数组
    search: function() {

        var billType_values = $("#billType").multiselect("getChecked").map(function(){ return this.value;}).get();
        $('#bill_type').val(billType_values);

        var bill_status_values =  $("#bill_status").multiselect("getChecked").map(function(){ return this.value;}).get();
        $('#billStatus').val(bill_status_values);
        var dt = $('#search_form').serializeArray();
        $("#flex").flexOptions({params: dt}).flexReload();

    },

    //重置
    reSet:function(){
        document.getElementById('search_form').reset();
        productSearch.load();
    },

    timeClear: function() {
        $('#send_date').val('');
    },

    //刷新页面
    load: function() {
        $("#flex").flexReload();
    },

    //订单详情
    billview: function( bill_no ) {
        window.open('/quanliadmin/app/bill/billSearch.pscript?operFlg=9&bill_no=' + bill_no);
    },

    //获取打印的行数
    brandPrintCheck:function( para ) {

        var print_array = new Array();

        $("input[name='billArr[]']").each(function(){
            if (this.checked) {
                print_array.push($(this).val());
            }
        });

        if (print_array.length == 0) {     //判断是否选中复选框，如果没有选择提示相应信息
            E.alert('请选择要打印的数据');
            return;
        }
        productSearch.print_array = print_array;


        if (para == 1) {
            Report.LoadFromURL('/report/SCD.grf?v=' + Math.floor(Math.random() * ( 1000 + 1)));
            $.each(print_array, function(k, v) {
                Report.LoadDataFromURL('/report/print_qs.php?print=0&bill_goods_no=' + v);
                Report.PrintPreview(true);
            });
        }

        if( para == 2 ){
            //验证是否已打印
            E.ajax_post({
                url: "/invokingAjax-backend/production/productionSearch.ajax?operFlg=4",
                data: {
                    printArr: print_array
                },
                call: function( o ) {
                    if (o.code == 202) {

                        //E.alert(o.message, 2, 'productSearch.load');
                        E.confirm(o.message,productSearch.execPrint);
                        return;
                    } else if(o.code == 200) {
                        productSearch.execPrint();
                    }else{
                        console.log(o);
                        E.alert(o.message);
                        return;
                    }
                }
            });
        }

    },

    //直接打印时执行打印
    execPrint:function(){
        E.loadding.open("执行中，请稍后...");


        E.ajax_post({
            url: "/invokingAjax-backend/production/productionSearch.ajax?operFlg=3",
            data: {
                print_array: productSearch.print_array
            },
            call: function( o ) {
                E.loadding.close();
                if (o.code == 200) {
                    //调用插件打印生产单
                    Report.LoadFromURL('/report/SCD.grf?v=' + E.createGuid());
                    $.each(productSearch.print_array, function(k, v) {
                        Report.LoadDataFromURL('/report/print_qs.php?print=1&bill_goods_no=' + v);
                        Report.Print(false);
                    });
                                        
                    E.alert(o.message, 3, 'productSearch.load');
                } else {
                    console.log(o);
                    E.alert(o.message);
                }
            }
        });

    }

};

$(window).ready(function() {

    $("#cityID").html("");

    var cityHtml = '<option value="">请选择</option>';

    $.ajax({
        type: "post",
        url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=1",
        dataType: "json",
        data: "",
        success: function( result_obj ) {
            if(result_obj.code == 200){
                $.each(result_obj.data, function(i,val){
                    cityHtml +='<option value="'+val.id+'">'+val.name+'</option>';
                });
                $('#cityID').html(cityHtml);
            }else{
                E.alert(result_obj.message);
            }
        }
    });

    //点击城市联动获得配送站(联动)
    $(document).on('change', '#cityID', function() {

        $('#distribution_id').html("");

        var cityID = $('#cityID').children('option:selected').val();
        var distributionHtml = '<option value="">请选择</option>';
        E.ajax_post({
            url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=2",
            data: {deliver_cityid: cityID},
            call: function( obj ) {
                if(obj.code ==200 && obj.data != null){

                    $.each(obj.data, function(i,val){
                        distributionHtml +='<option value="'+val.distribution_id+'">'+val.distribution_name+'</option>';
                    });
                    $('#distribution_id').html(distributionHtml);
                }else{

                    distributionHtml += '';
                    $('#distribution_id').html(distributionHtml);
                }
            }
        });
    });
});


</script>

</body>
</html>